# -*- coding: utf-8 -*
'''
    Created by XiaoInk at 2021/10/10 18:13:02
    Gitee: https://gitee.com/XiaoInk
'''

from typing import Dict

from app import mysql_r, mysql_w


def find_by_id(id: int) -> Dict or None:
    return mysql_r.execute('select * from user where id=%s;', (id,))


def find_by_username(username: str) -> Dict or None:
    return mysql_r.execute('select * from user where username=%s;', (username,))


def create(username: str, password: str) -> Dict:
    mysql_w.execute('insert into user (username, password) values (%s,%s);', (username, password))
    return find_by_username(username)


if __name__ == '__main__':
    pass
